/**
 * 
 */
package x.java.tea.util;

import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;

import x.java.tea.ObjectTreeNode;
import x.java.tea.TreeNode;

/**
 * @author qiangli
 *
 */
public class FileTreeNode extends ObjectTreeNode {

	/**
	 * @param object
	 */
	public FileTreeNode(File object) {
		super(object);
	}

	@Override
	public Iterator<TreeNode> children() {
		File f = (File) object;
		File[] fl = f.listFiles();
		if (fl == null) {
			return null;
		}
		ArrayList<TreeNode> nl = new ArrayList<TreeNode>();
		for (int i = 0; i < fl.length; i++) {
			nl.add(new FileTreeNode(fl[i]));
		}
		return nl.iterator();
	}

	@Override
	public TreeNode getParent() {
		File f = (File) object;
		return new FileTreeNode(f.getParentFile());
	}

	@Override
	public boolean isLeaf() {
		File f = (File) object;
		return f.isFile();
	}
}
